package com.archway.appframe.service;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Configuration
@EnableTransactionManagement
public class AppframeTransactionConfig {
	/**
	 * 显式设定超时
	 */
	private final int DEFAULT_TIMEOUT=30;
	
	@Autowired
	private DataSource datasource;
	
	
	@Bean(name="transactionManager")
	public PlatformTransactionManager transactionManager(){
		DataSourceTransactionManager dtm = new DataSourceTransactionManager();
		dtm.setDataSource(this.datasource);
		dtm.setDefaultTimeout(DEFAULT_TIMEOUT);
		return dtm;
	}
	
}
